package com.pig4cloud.pig.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.demo.dto.Result;
import com.pig4cloud.pig.demo.dto.SmartAppGoodsCategoryDto;
import com.pig4cloud.pig.demo.entity.SmartAppGoodsCategory;
import com.pig4cloud.pig.demo.service.SmartAppGoodsCategoryService;
import com.pig4cloud.pig.demo.mapper.SmartAppGoodsCategoryMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class SmartAppGoodsCategoryServiceImpl extends ServiceImpl<SmartAppGoodsCategoryMapper, SmartAppGoodsCategory>
    implements SmartAppGoodsCategoryService{

	@Override
	public Result<List<SmartAppGoodsCategoryDto>> getList() {

		List<SmartAppGoodsCategory> list = this.list();
		List<SmartAppGoodsCategoryDto> smartAppGoodsCategoryDtos = BeanUtil.copyToList(list, SmartAppGoodsCategoryDto.class);
		return new Result<>(200, "success", smartAppGoodsCategoryDtos);
	}

	@Override
	public Result<SmartAppGoodsCategoryDto> getById(Long id) {
		SmartAppGoodsCategory byId = super.getById(id);
		SmartAppGoodsCategoryDto smartAppGoodsCategoryDto = BeanUtil.copyProperties(byId, SmartAppGoodsCategoryDto.class);
		return new Result<>(200, "success", smartAppGoodsCategoryDto);
	}

	@Override
	public Result add(SmartAppGoodsCategoryDto categoryDto) {
		SmartAppGoodsCategory smartAppGoodsCategory = BeanUtil.copyProperties(categoryDto, SmartAppGoodsCategory.class);
		this.save(smartAppGoodsCategory);
		return new Result(200,"success", null);
	}

	@Override
	public Result update(SmartAppGoodsCategoryDto categoryDto) {
		SmartAppGoodsCategory smartAppGoodsCategory = BeanUtil.copyProperties(categoryDto, SmartAppGoodsCategory.class);
		this.updateById(smartAppGoodsCategory);
		return new Result(200,"success", null);
	}

	@Override
	public Result delete(Long id) {
		this.removeById(id);
		return new Result(200,"success", null);
	}
}




